//
//  HGScroll.m
//  HiGo
//
//  Created by Think_lion on 15/7/26.
//  Copyright (c) 2015年 Think_lion. All rights reserved.
//

#import "HGScroll.h"
//#import "HGScrollModel.h"
#import "HGScrollCell.h"
#define  MaxCount 100

#define HGScrollName  @"scrollNameCell"

@interface HGScroll ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic,weak) UICollectionView *scrollCollection;

@end

@implementation HGScroll



-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if(self){
        //1.添加collectionView
        [self add];
     
    }
    return self;
}


//-(NSIndexPath*)resetIndexPath
//{
//    NSIndexPath *currentIndexPath=[[self.scrollCollection indexPathsForVisibleItems] lastObject];
//    NSIndexPath *currentIndexPathReset=[NSIndexPath indexPathForItem:currentIndexPath.item inSection:MaxCount/2];
//    
//    [self.scrollCollection scrollToItemAtIndexPath:currentIndexPathReset atScrollPosition:UICollectionViewScrollPositionLeft animated:NO];
//    return currentIndexPathReset;
//}

#pragma mark 定时器下一页的方法
#pragma mark 添加CollectionView
-(void)add
{
    //1添加模型
//    NSArray *plist=[HGScrollModel objectArrayWithFilename:@"newses.plist"];
    //[self.arr addObjectsFromArray:plist];
    
    UICollectionViewFlowLayout *flow=[[UICollectionViewFlowLayout alloc]init];
   // flow.minimumLineSpacing=0;
    
    flow.scrollDirection=UICollectionViewScrollDirectionHorizontal;
    flow.itemSize=self.frame.size;
    
    UICollectionView *collectionView=[[UICollectionView alloc]initWithFrame:self.bounds collectionViewLayout:flow];
    
    [collectionView registerClass:[HGScrollCell  class] forCellWithReuseIdentifier:HGScrollName];
   // collectionView.showsHorizontalScrollIndicator=NO;
    collectionView.delegate=self;
    collectionView.dataSource=self;
    //collectionView.pagingEnabled=YES;
    [self addSubview:collectionView];
    self.scrollCollection=collectionView;
    
}

#pragma mark  每一组返回多少行
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

#pragma mark 返回单元
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HGScrollCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:HGScrollName forIndexPath:indexPath];
    
    //cell.backgroundColor=[UIColor redColor];
   // HGScrollModel *model=self.arr[indexPath.item];
   // cell.scrollModel=model;
    return cell;
    
}



@end
